<template>
  <div class="main" v-color="'bgkImg'">
    <dz-nav :is-back="true" back-url="/buy">
      <template #center>
        <b v-color><qq>Join</qq></b>
      </template>
      <template #right>
        <div class="right-nav" v-routers="{path:'/purchasing'}">
          <img src="@/assets/images/Component3.png" alt="">
          <span><qq>Tutorial</qq></span>
        </div>
      </template>
    </dz-nav>

    <div class="box-1">
      <div class="box-center">
        <div class="titles">
          <img src="@/assets/images/vip.png" alt="">
        </div>
        <div class="bottom-box">
          <div class="tip">{{ form.sellingPrice }}USDT</div>
        </div>
      </div>
    </div>

    <div class="box-1 box-2">
      <div class="box-center-1">
        <div class="top">{{ form.vipType }}</div>
        <div class="vip-info">
            <div class="box-nav">
              <img src="@/assets/images/icon_2.png" alt="">
              <div class="right">
                <p class="title"><qq>Numberoftasksperday</qq></p>
                <p class="content">{{ form.numberOfTasks }}</p>
              </div>
            </div>
          <div class="box-nav">
            <img src="@/assets/images/icon_3.png" alt="">
            <div class="right">
              <p class="title"><qq>Taskunitprice</qq></p>
              <p class="content">{{form.dailyIncome}}USDT</p>
            </div>
          </div>
          <div class="box-nav">
            <img src="@/assets/images/icon_1.png" alt="">
            <div class="right">
              <p class="title"><qq>Validityperiod</qq></p>
              <p class="content">365</p>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="bottom">
      <dz-button @click="show=true"><qq>Join</qq></dz-button>
    </div>

    <dz-safe></dz-safe>

    <van-popup
        closeable
        :overlay="false"
        v-model="show"
        position="bottom"
        :style="{ height: '90%' }"
        round>
      <div class="box-3">
        <div class="btn-box" @click="toRecharge(item)" v-for="(item,index) in payments" :key="index">
          <img :src="item.img" alt="">
          <span>{{ item.name }}</span>
        </div>
      </div>
    </van-popup>
  </div>
</template>

<script>
import {createRechargeOrder, getChannelTypeIsopen, payChannel, vipMessage} from "@/api/apiFox";
import {setSessionItem} from "@/utils/auth";

  export default {
    data(){
      return{
        list:[],
        payments:[],
        form:{},
        payMethod:[],
        show:false
      }
    },
    methods:{
      getPayChannels() {
        payChannel().then(res => {
          this.payMethod = res.data
        }).catch(err => {})
      },
      getList(id){
        vipMessage().then(res=>{
          this.list = res
         let s =  res.filter(value=>{return value.idw===id})
          console.log(s)
          if (s && s.length>0){
            this.form = s[0]
          }

        }).catch(err=>{})
      },

      toRecharge(item){
        if (item.id === 6){
          console.log(item)
          this.$router.push({path:'/payment',query:{money:this.form.sellingPrice}}).catch(err=>{})
        }else{
          let f = {
            amount: this.form.sellingPrice,
            channelName: this.payMethod[0].channelName,
            channelType:item.channelType
          }
          createRechargeOrder(f).then(res => {
            setSessionItem('pay',res.data)
            this.$router.push({path:'/pay'}).catch(err=>{})
          }).catch(err => {})
        }

      },

      getPay(){
        getChannelTypeIsopen().then(res=>{
          let s = [
            {id:1,name:'USDT.TRC20',img:require('@/assets/images/TRC20.png'),channelType:res.trc20,isOpen:res.withdrawal_trc20},
            {id:2,name:'USDT.ERC20',img:require('@/assets/images/TRC20.png'),channelType:res.erc20,isOpen:res.withdrawal_erc20},
            {id:3,name:'USDT.Polygon',img:require('@/assets/images/Polygon.png'),channelType:res.polygon,isOpen:res.withdrawal_polygon},
            {id:4,name:'USDC.Polygon',img:require('@/assets/images/Polygon.png'),channelType:res.usdc_polygon,isOpen:res.withdrawal_usdc_polygon},
            {id:5,name:'ETH',img:require('@/assets/images/Property1=USDT.png'),channelType:res.default,isOpen:1},
            {id:6,name:'balance payment',img:require('@/assets/images/bt.png'),channelType:res.default,isOpen:1},
          ]
          this.payments = s.filter(value => {return parseInt(value.isOpen) === 1})
        }).catch(err=>{})
      }
    },
    mounted() {
      this.getPay()
      this.getPayChannels()
      this.getList(this.$route.query.uid)
    }
  }
</script>

<style scoped lang="scss">
.main{
  width: 100%;
  min-height: 100vh;
  .right-nav{
    width: 90px;
    height: 35px;
    background: #FFFFFF;
    border-radius: 20px 20px 20px 20px;
    border: 1px solid #E08821;
    box-sizing: border-box;
    margin-left: -15px;
    margin-top: 3px;
    z-index: 99;
    position: absolute;
    font-weight: 500;
    font-size: 12px;
    color: #E08821;
    display: flex;
    justify-content: center;
    align-items: center;
    img{
      width: 28px;
      height: 28px;
    }
  }
  .box-1{
    width: 100%;
    min-height: 200px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 40px;
    .box-center{
      width: 331px;
      background: url('@/assets/images/CARD_1.png') no-repeat;
      background-size: 100%;
      height: 148px;
      border-radius: 10px;
      position: relative;
      .titles{
        width: 100%;
        text-align: center;
        margin-top: -30px;
        img{
          width: 122px;
          height: 123px;
          object-fit: cover;
        }
      }
      .bottom-box{
        width: 100%;
        height: 40px;
        display: flex;
        justify-content: center;
        align-items: center;
        .tip{
          width: 185px;
          height: 47px;
          background: rgba(255,184,41,0.37);
          border-radius: 30px 30px 30px 30px;
          font-weight: bold;
          font-size: 28px;
          color: #533DF1;
          display: flex;
          justify-content: center;
          align-items: center;
        }
      }
    }
    .box-center-1{
      width: 324px;
      height: 253px;
      background: #FFFFFF;
      border-radius: 10px;
      .top{
        width: 324px;
        height: 40px;
        background: #FFFFFF;
        border-radius: 10px 10px 0px 0px;
        font-weight: bold;
        font-size: 20px;
        color: #000000;
        text-align: center;
        line-height: 40px;
      }
      .vip-info{
        width: 324px;
        height: 213px;
        background: #F2F2F2;
        border-radius: 0px 0px 10px 10px;
        padding: 22px 15px;
        box-sizing: border-box;
        .box-nav{
          width: 100%;
          height: 42px;
          display: flex;
          justify-content: space-between;
          margin-bottom: 18px;
          img{
            object-fit: cover;
            width: 42px;
            height: 42px;
            margin-right: 10px;
          }
          .right{
            width: 100%;
            .title{
              font-weight: bold;
              font-size: 14px;
              color: #666666;
            }
            .content{
              font-weight: bold;
              font-size: 14px;
              margin-top: 6px;
              color: #373737;
            }
          }
        }
      }
    }
  }
  .box-2{
    margin-top: 10px;
  }
  .bottom{
    width: 100%;
    height: 100px;
    padding: 0 16px;
    box-sizing: border-box;
    position: absolute;
    bottom: 0;
    left: 0;
  }
  .box-3{
    width: 100%;
    padding:20px 28px;
    box-sizing: border-box;
    .btn-box{
      width: 320px;
      margin-top: 20px;
      height: 100px;
      background: #FFFFFF;
      border-radius: 20px 20px 20px 20px;
      box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 12px;
      display: flex;
      align-items: center;
      padding: 0 24px;
      box-sizing: border-box;
      img{
        margin-right: 10px;
        width: 60px;
        height: 60px;
        object-fit: cover;
      }
      span{
        font-weight: bold;
        font-size: 20px;
        color: #5A4CBB;
      }
    }
  }
  ::v-deep(.van-popup){
    background: linear-gradient( 180deg, #FFF0C9 0%, #D49188 100%);
    box-shadow: inset 0px 4px 4px 0px rgba(255,255,255,0.25);
  }
}
</style>